/**
 * 商家模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";


	var winWidth=0;
	window.onload=winChange;
	window.onresize=winChange;
	function winChange(){
		if (window.innerWidth){
	       winWidth = window.innerWidth;
	    }else if ((document.body) && (document.body.clientWidth)){
	       winWidth = document.body.clientWidth;		
		}	
		if(winWidth>=800&&winWidth<980){
				$("body").removeClass();
			    $("body").addClass("container_800");
		}else if(winWidth>=980&&winWidth<1280){
				$("body").removeClass();
				$("body").addClass("container_980");						
		}else if(winWidth>=1280&&winWidth<1400){
				$("body").removeClass();
				$("body").addClass("container_1280");
		}else if(winWidth>=1400){
				$("body").removeClass();
		}
	}
	
	
	
	$(function(){
		//商家主页一级分类切换
		$(document).on("click",".ldh-header-classNav span",function(){
			$(this).addClass("on").siblings().removeClass("on")	
		});
		$(document).on("focus","a,input:button,input:submit,button,input:checkbox,input:radio",function(){this.blur()});
		$(document).on("click","#ldh-cart .ldh-cart-nav",function(){
			if(!$(this).parent().hasClass("on")){
				$(this).parent().addClass("on");	
				$ldh_cart.getCartList(exports.getShopId());
			}else{$(this).parent().removeClass("on");}
			/*$(document).on("click",function(event){
				var _target=$(event.target).parents();
				if(!_target.hasClass("ldh-cart")){$("#ldh-cart").removeClass("on");}			
			});*/
		});
		
	});
	//商品详情翻页
	function propicRoll(){
		var li_num=$(".ldh-productbtn-pic li").length;
		 var num=6;//显示数量
		 var ul_width=li_num*61;
		 var one_width=61*num;
		 var ul_left=0;
		 $(".ldh-productbtn-pic").css("width",one_width+"px");;
		 if(li_num>num){		 
			 $(".ldh-productbtn-pic ul").css("width",ul_width+"px");
			 var max_left=ul_width-one_width;
			 $(".ldh-productbtn-l").click(function(){
				 if(ul_left<0){
					 ul_left=ul_left+one_width;
					 $(".ldh-productbtn-pic ul").animate({left:ul_left},500);	 
				 }
			 });  
			 $(".ldh-productbtn-r").click(function(){
				 if(ul_left>-max_left){
					 ul_left=ul_left-one_width;
					 $(".ldh-productbtn-pic ul").animate({left:ul_left},500);	
				 }
				 
			 });
		 }	
	}
	
	var merchandiseTypeId="",merchandiseName="",sort="0",pageSize=24;
	
	var validate = require("../../custom/base/component-validate.js");
	
	require("../../custom/base/component-core.js");
	
	var base = require("../../custom/base/component-base.js");
	
	base.init(base);
	
	var cart=require("../../custom/cart/module-cart.js");
	
	cart.init(cart);

	var async = require("../../custom/base/component-async.js");
	
	require("../../custom/base/component-md5.js");
	
	require("../../custom/base/component-page.js");
	
	var head=require("../../custom/head/module-head.js");
	
	head.init(head);
	
	//设置商家代码
	exports.setShopId=function(shopId){
		
		this.shopId=shopId;
		
	};
	
	//获取商家代码
	exports.getShopId=function(){
		
		return this.shopId;
		
	};
	
	//设置列表页码
	exports.setCurrentPage=function(currentPage){
		
		this.currentPage=currentPage;
		
	};
	
	//获取列表页码
	exports.getCurrentPage=function(){
		
		return this.currentPage==null?1:this.currentPage;
		
	};
	
	
	//初始化函数
	exports.init=function(m){
		
		window.$ldh_shop=m;
		
		base.setFromPage("shopIndex");
		
		var url=decodeURI(document.URL);
		
		var shopId=$("#shopId").val();
		
		if(validate.isNull(shopId)){
			
			if(url.indexOf("?")>0){
				
				if(url.indexOf("#")>=0){
					
					url=url.substring(0,url.indexOf('#'));
					
				}
				
				var params=url.split("?")[1];
				
				params=base.decodeParams(params);
				
				
				if(params.indexOf("&")>=0){
					
					params=params.split("&")[0];
					
				}
				
				shopId=params.split("=")[1];
				
				//alert(base.decodeParams("%23%23s%25h%23o%25p%23I%25d%23%3D%252%230%251%234%251%232%251%237%251%237%250%230%255%237%250%231%252%239%25%23%23"));
				
			}
		}
		
		if(validate.isNull(shopId))
		{
			window.location.href=ctx+"/v1/pages/404.jsp";
			return;
		}
		
		exports.setShopId(shopId);
		
		//exports.getShopDetail(exports.getShopId());
		var userId=$("#session_userid").val();
		if(!validate.isNull(userId)){
			
			base.hasLoginShow(userId,$("#session_username").val(),$("#session_iconurl").val());
		}else{
			
			base.noLoginShow();
		}
		
		getShopMerchandiseType();
		
		getShopMerchandise();
				
		
		cart.setShopId(shopId);
		
		
		
	};
	

	//查询商家基本信息
	exports.getShopDetail=function(shopId){
		
		
		var params = {
			shopId:shopId
		};
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/ShopDetail/shopDetail.do", params));

					
							if(data["code"]==1){
								
								
								if(validate.isNull(data["shop"]))
								{
									window.location.href=ctx+"/v1/pages/404.jsp";
									return;
								}
								
								
								var shopId = data["shop"]["shopId"];
								var shopName = data["shop"]["shopName"];
								var logoUrl = data["shop"]["logoUrl"];
								var businessHours = data["shop"]["businessHours"];
								var minAmount = data["shop"]["minAmount"];
								var address = data["shop"]["address"];
								var range= data["shop"]["range"];
								var introduce=data["shop"]["introduce"];
								var speId=data["shop"]["speId"];
								var phone=data["shop"]["phone"];
								var mobile=data["shop"]["mobile"];
								var score=data["shop"]["score"];
								var businessStatus=data["shop"]["businessStatus"];
								var typeIcon=data["shop"]["typeIcon"];
								var memberFlag=data["shop"]["memberFlag"];
								
								if(introduce=="")
									introduce="暂无";
								
								if(range=="" || range=="0"){
									range="不限";
								}else{
									range=range+"米";
								}
								
								
								
								$("#shopId").val(shopId);
								//$("#business_Status").val(businessStatus);
								
								if(typeIcon=="" || typeIcon.indexOf(".")<0){
									
									typeIcon= ctx+'/v1/img/category_f.png';
								}else{
									
									typeIcon= ctx+'/v1/img/'+typeIcon;
								}
								
								$("#shopTypeName").html(data["shop"]["shopTypeName"]);
								$("#shopTypeIcon").attr("src",typeIcon);
								
								
								if(memberFlag=="" || memberFlag=="0"){
									
									setConcernButton(0);
									
								}else{
									setConcernButton(1);
								}
								
								if(minAmount=="" || minAmount=="0"){
									minAmount="不限";
								}else{
									minAmount=minAmount+"元";
								}
								
								if(businessHours=="" || businessHours=="0"){
									businessHours="不限";
								}
								
								if(businessStatus=="1"){
									
									businessStatus="营业中";
									
									$(".ldh-main-left").css("background-image","url("+ctx+"/v1/img/roof_open.png)");
																		
								}else if(businessStatus=="2"){
									
									businessStatus="休息中";
									
									
									$(".ldh-store-state").css("background-color","#666666");
									
									$(".ldh-main-left").css("background-image","url("+ctx+"/v1/img/roof_close.png)");
									
								}else {
									
									businessStatus="审核中";
									
									$(".ldh-store-state").css("background-color","#666666");
									
									$(".ldh-main-left").css("background-image","url("+ctx+"/v1/img/roof_close.png)");
								}
								
							
								
								if(logoUrl=="" || logoUrl.indexOf(".")<0){
									
									logoUrl= ctx+'/v1/img/category_f.png';
								}else{
									
									logoUrl=fileOpenUrl+logoUrl;
								}
								
								$("#shopName").html(shopName);
								$("#topShopName").html(shopName);
								$("#logoUrl").attr("src",logoUrl);
								$("#topLogoUrl").attr("src",logoUrl);
								$("#shopSpe").html(base.getSpeHtml(speId));
								$("#introduce").html(introduce);
								$("#phone").html(phone);
								//$("#mobile").html(mobile);
								$("#businessHours").html(businessHours);
								$("#range").html(range);
								$("#minAmount").html(minAmount);
								$("#address").html(address);
								$("#score").css("width",((score/5)*100)+"%");
								$("#businessStatus").html(businessStatus);
								/* <div id="down_qrcode" style="opacity:0; position:absolute; width:0px; height:0px; top:0; overflow:hidden;"></div>             
							        <!-- 用来校验该浏览器是否支持HTML5 -->*/
							      
							        
								$("#div_other").html('<canvas id="Canvas"></canvas><a href="####" class="ldh-godownload">本店二维码<i id="down_qrcode"></i></a><a href=javascript:$ldh_shop.goShopPhoto()>查看店铺相册</a>');
								
								var q_text = "http://www.storeme.cn/mall/v1/pages/shop/shopIndex.jsp?shopId="+shopId;
								//生成二维码
							    $("#down_qrcode").qrcode({
							          text: utf16to8(q_text),
							          height: 120,
							          width: 120
							        });
								
								//把title变成商家名称
								document.title="云便利商店  "+shopName;
								
								//删除百度分享双击选中文字弹出的分享框
								$(".bdselect_share_box").remove();
								
							}
							
						

				}))().start();
	};
	
	//转码
	function utf16to8(str) { 
		  var out, i, len, c;
		  out = "";
		  len = str.length;
		  for (i = 0; i < len; i++) {
		    c = str.charCodeAt(i);
		    if ((c >= 0x0001) && (c <= 0x007F)) {
		        out += str.charAt(i);
		    } else if (c > 0x07FF) {
		        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
		        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
		        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
		    } else {
		        out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
		        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
		    }
		  }
		  return out;
	}
	
	//查询商家商品分类
	function getShopMerchandiseType(){
		

		var params = {
				shopId : exports.getShopId()
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/GoodsType/queryAllMerchandiseTypelistByShopId.do", params));
						
						
						if(data["code"]==1){
		
							var htmlStr="";
							
							var length=data["goodsTypeList"].length;
							
							
							//$("#hotTypeList").append('<li onclick=$ldh_shop.setMerchandiseType("")><span>全部</span></li>');
							/*if(length>5)
								length=5;*/
							for (var i = 0; i < length; i++) {

								//htmlStr += '<li><span>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></li>';
								if($("#hotTypeList li").length<4){
									//$("#hotTypeList").append('<li onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'")><span>'+base.subString(data["goodsTypeList"][i]["merchandiseTypeName"],6)+'</span></li>');

								}

											if(length<=4){
												
												htmlStr += '<li>';
												htmlStr += '<div class="ldh-navClassall-dlbox">';
												htmlStr += '<dl>';
												htmlStr += '<dt onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></dt>';
												if(data["goodsTypeList"][i]["childTypeList"].length>=1){
													htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeName"],6)+'</span></dd>';
												}
												if(data["goodsTypeList"][i]["childTypeList"].length>=2){
													htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeName"],6)+'</span></dd>';
												}
												if(data["goodsTypeList"][i]["childTypeList"].length>=3){
													htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeName"],6)+'</span></dd>';
												}
												htmlStr += '</dl>';
												htmlStr += '</div>';
												htmlStr += '<div class="ldh-navClassall-list2">';
												htmlStr += '<div class="ldh-navClassall-c">';
												htmlStr += '<h3><span onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></h3>';
												htmlStr += '<div>';
												for(var j=0;j<data["goodsTypeList"][i]["childTypeList"].length;j++){
													
													htmlStr += '<p onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeName"]+'</span></p>';

												}
												htmlStr += '</div></div>';
											/*	htmlStr += '<div class="ldh-navClassall-c">';
												htmlStr += '<h3><span>个人护理</span></h3>';
												htmlStr += '<div><p><span>BB霜</span></p><p><span>SK-t</span></p><p><span>玉兰油</span></p></div>';
												htmlStr += '</div>';
												htmlStr += '</div>';*/
												htmlStr += '</li>';
											}else{
												
												htmlStr += '<li>';
												htmlStr += '<div class="ldh-navClassall-dlbox">';
												htmlStr += '<dl>';
												
												if(i+1<length){
													htmlStr += '<dt onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+"/"+data["goodsTypeList"][i+1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+"/"+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["merchandiseTypeName"]+"/"+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'</span></dt>';
												
													
													if(data["goodsTypeList"][i]["childTypeList"].length>=1){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i]["childTypeList"].length>=2){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i]["childTypeList"].length>=3){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i+1]["childTypeList"].length>=1){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i+1]["childTypeList"][0]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["childTypeList"][0]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i+1]["childTypeList"][0]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i+1]["childTypeList"].length>=2){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i+1]["childTypeList"][1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["childTypeList"][1]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i+1]["childTypeList"][1]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i+1]["childTypeList"].length>=3){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i+1]["childTypeList"][2]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["childTypeList"][2]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i+1]["childTypeList"][2]["merchandiseTypeName"],6)+'</span></dd>';
													}
													
													
												}else{
													
													htmlStr += '<dt onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></dt>';

													if(data["goodsTypeList"][i]["childTypeList"].length>=1){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][0]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i]["childTypeList"].length>=2){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][1]["merchandiseTypeName"],6)+'</span></dd>';
													}
													if(data["goodsTypeList"][i]["childTypeList"].length>=3){
														htmlStr += '<dd onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+base.subString(data["goodsTypeList"][i]["childTypeList"][2]["merchandiseTypeName"],6)+'</span></dd>';
													}
												}
												
												
												
												htmlStr += '</dl>';
												htmlStr += '</div>';
												htmlStr += '<div class="ldh-navClassall-list2">';
												
												if(i+1<length){
													
													htmlStr += '<div class="ldh-navClassall-c">';
													htmlStr += '<h3><span onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></h3>';
													htmlStr += '<div>';
													for(var j=0;j<data["goodsTypeList"][i]["childTypeList"].length;j++){
														
														htmlStr += '<p onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeName"]+'</span></p>';

													}
													htmlStr += '</div></div>';
												    
													htmlStr += '<div class="ldh-navClassall-c">';
													htmlStr += '<h3><span onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i+1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'")>'+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'</span></h3>';
													htmlStr += '<div>';
													for(var j=0;j<data["goodsTypeList"][i+1]["childTypeList"].length;j++){
														
														htmlStr += '<p onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i+1]["childTypeList"][j]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["childTypeList"][j]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i+1]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i+1]["childTypeList"][j]["merchandiseTypeName"]+'</span></p>';

													}
													htmlStr += '</div></div>';
													
													i=i+1;
													
												}else{
													
													htmlStr += '<div class="ldh-navClassall-c">';
													htmlStr += '<h3><span onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")>'+data["goodsTypeList"][i]["merchandiseTypeName"]+'</span></h3>';
													htmlStr += '<div>';
													for(var j=0;j<data["goodsTypeList"][i]["childTypeList"].length;j++){
														
														htmlStr += '<p onclick=$ldh_shop.setMerchandiseType("'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeName"]+'","'+data["goodsTypeList"][i]["merchandiseTypeId"]+'","'+data["goodsTypeList"][i]["merchandiseTypeName"]+'")><span>'+data["goodsTypeList"][i]["childTypeList"][j]["merchandiseTypeName"]+'</span></p>';

													}
													htmlStr += '</div></div>';
												/*	htmlStr += '<div class="ldh-navClassall-c">';
													htmlStr += '<h3><span>个人护理</span></h3>';
													htmlStr += '<div><p><span>BB霜</span></p><p><span>SK-t</span></p><p><span>玉兰油</span></p></div>';
													htmlStr += '</div>';
													htmlStr += '</div>';*/
												}
											
												htmlStr += '</li>';
												
												
											}
											

							}
							
							$("#shopMerchandiseTypeList").html(htmlStr);

						}
						
						
					}))().start();
			
	}
	
	//设置商品分类
	var merchandiseTypeName="";
	
	exports.setMerchandiseType=function(id,typeName,parentId,parentTypeName){
		
		$('html, body').animate({scrollTop:0}, 'slow');
		
		merchandiseTypeId=id;
		
		exports.setCurrentPage(1);
		
		merchandiseName="";
		
		$("#merchandiseName").val("");
		
		$("#merchandiseList").html("");
				
		getShopMerchandise();
		
		
		if(!validate.isNull(typeName)){
			
			$("#div_currentType").show();
			
			if(validate.isNull(parentTypeName)){
				
				$("#currentTypeName").html('分类：<a href=javascript:$ldh_shop.setMerchandiseType("","")>全部</a> ＞ '+typeName);
				
			}else{
				
				$("#currentTypeName").html('分类：<a href=javascript:$ldh_shop.setMerchandiseType("","")>全部</a> ＞  <a href=javascript:$ldh_shop.setMerchandiseType("'+parentId+'","'+parentTypeName+'")>'+parentTypeName+'</a> ＞ '+typeName);
			}
			
			
		}else{
			
			$("#div_currentType").hide();
		}
		
		merchandiseTypeName=typeName;
	
	};
	
	// 搜索商家商品
	exports.searchMerchandise=function(){
		
		merchandiseName=$("#merchandiseName").val();
		
		if(merchandiseName=="搜索本店商品"){
			
			return;
		}
		
		merchandiseTypeName="";
		
		merchandiseTypeId="";
		
		$("#div_currentType").hide();
		
		exports.setCurrentPage(1);
		
		$("#merchandiseList").html("");
		
		getShopMerchandise();
		
	};
	
	
	// 获取商家商品
	function getShopMerchandise(){
		
		
		var params = {
				shopId : exports.getShopId(),
				goodName:merchandiseName,
				goodType:merchandiseTypeId,
				sort: sort,
				pageSize : pageSize,
				currentPage : exports.getCurrentPage()
		};
		
		$('#footPage').html("");
		
		base.showLoading("#merchandiseList");
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Goods/goodsList.do", params));
						
						
						base.cancelLoading("#merchandiseList");
						
						if(data["code"]==1){
							
							var htmlStr="";

																	
							for (var i = 0; i < data["goodsList"].length; i++) {
								
											var obj=data["goodsList"][i];
											var isDiaPlay="display:none;";
											if(!validate.isNull(obj["isCartNum"]) && parseInt(obj["isCartNum"])>0){
												isDiaPlay="display:inline;";
											}
											//alert("isCartNum=="+obj["isCartNum"]);
											var _merchandiseName=obj["merchandiseName"];
											if(_merchandiseName.toString().length>12){
												_merchandiseName=_merchandiseName.toString().substring(0,11)+"...";
											}
											htmlStr += '<div class="ldh-goods-box">';
											htmlStr += '<div class="ldh-gb-top">';
											
											if(validate.isNull(obj["picDefault"])){
												
												///htmlStr += '<img class="lazy"  id="'+obj["merchandiseId"]+'"  data-original="'+ctx+'/v1/img/default_234_220.png" />';
												htmlStr += '<img class="lazy" onclick=$ldh_shop.loadMerchandiseDetail('+i+',"'+obj["merchandiseId"]+'") id="'+obj["merchandiseId"]+'"  src="'+ctx+'/v1/img/default_234_220.png" />';

											}else{
												
											//	htmlStr += '<img class="lazy"  id="'+obj["merchandiseId"]+'" onload=$ldh_base.ResizeImage("'+obj["merchandiseId"]+'") data-original="'+fileOpenSourceUrl+obj["picDefault"]+'" />';
												
												htmlStr += '<img class="lazy" onclick=$ldh_shop.loadMerchandiseDetail('+i+',"'+obj["merchandiseId"]+'")  id="'+obj["merchandiseId"]+'" onload=$ldh_base.ResizeImage("'+obj["merchandiseId"]+'") src="'+fileOpenSourceUrl+obj["picDefault"]+'" />';

											}
											
											htmlStr += '</div>';
											
											if(obj["recommended"]=="1"){
												
												htmlStr += '<i class="ldh-recommend"></i>';
											}
											htmlStr += '<div class="ldh-gb-main">';
											htmlStr += '<h3 title='+obj["merchandiseName"]+'>'+_merchandiseName+'</h3>';
										
											
											if(!validate.isNull(obj["brief"])){
												htmlStr += '<p title="'+obj["brief"]+'">'+base.subString(obj["brief"],30)+'</p>';
											}else{
												htmlStr += '<p title="'+obj["merchandiseName"]+'">'+base.subString(obj["merchandiseName"],30)+'</p>';
											}
											htmlStr += '</div>';
											htmlStr += '<div class="ldh-gb-bottom clearfix">';
											htmlStr += '<div class="fl-left">';
											var unitName=obj["unitName"];
											if(!validate.isNull(obj["unitName"])){
												
												unitName="/"+unitName;
											}
											htmlStr += '<p class="ldh-goods-sj" style="font-size:20px">¥'+obj["price"].toFixed(2)+unitName+'</p>';
											if(obj["mktprice"]>obj["price"]){
												htmlStr += '<p class="ldh-goods-scj" style="font-size:16px">¥'+obj["mktprice"].toFixed(2)+unitName+'</p>';
											}
											htmlStr += '</div>';
											htmlStr += '<div class="fl-right">';
											htmlStr += '<input type="hidden" id="cartId'+exports.getCurrentPage()+i+'" value="'+obj["cartId"]+'"/>';
											htmlStr += '<button type="button" class="ldh-goods-sub" id="sub_'+obj["merchandiseId"]+'" onclick=$ldh_cart.deleteCartNum(this,"'+obj["merchandiseId"]+'","'+obj["price"]+'",'+exports.getCurrentPage()+i+') style="'+isDiaPlay+'"></button>';
											htmlStr += '<button type="button" class="ldh-goods-add" onclick=$ldh_cart.addCartNum(this,0,"'+exports.getShopId()+'","'+obj["merchandiseId"]+'","'+obj["price"]+'",'+exports.getCurrentPage()+i+')></button>';
											htmlStr += '</div>';
											htmlStr += '</div>';
											htmlStr += '<div class="ldh-gb-num" id="hasBuy_'+obj["merchandiseId"]+'" style="'+isDiaPlay+'"><span>'+obj["isCartNum"]+'</span><span></span></div>';
											htmlStr += '</div> ';
											
											$("#merchandiseList").append(htmlStr);
											
											htmlStr="";
											
						   }
							
							if(data["goodsList"].length==0)
							{
								if(validate.isNull(merchandiseName) && validate.isNull(merchandiseTypeName)){
									htmlStr+='<div class="ldh-cart-null"><p>找不到商品!</p></div>	';

								}else if(!validate.isNull(merchandiseName)){
									htmlStr+='<div class="ldh-cart-null"><p>亲,抱歉哦！没有找到与“<font color="#ed5d3a!important">'+merchandiseName+'</font>”相关的商品呢!</p></div>	';

								}else if(!validate.isNull(merchandiseTypeName)){
									htmlStr+='<div class="ldh-cart-null"><p>亲,抱歉哦！没有找到分类为“<font color="#ed5d3a!important">'+merchandiseTypeName+'</font>”的相关商品呢!</p></div>	';
								}
								
								$("#merchandiseList").append(htmlStr);
								
								
								
							}else{
																
								
								$('#footPage').ldh_pagination_shoplist(pageSize,parseInt(exports.getCurrentPage()),data["totals"],data["pages"],{  
									 
									 changePageCallback:function(pageSize,page){  
										
										 $('html, body').animate({scrollTop:0}, 0);
										 
										 exports.setCurrentPage(page);
										 
										 $("#merchandiseList").html("");
										 
										 getShopMerchandise();
										 
									 },
									 changePageSizeCallBack:function(pageSize){
									 } 
						         }); 
								
								/*$("img.lazy").lazyload({
									placeholder : ctx+"/v1/img/transparent.gif", 
									effect: "fadeIn"
								});*/
							}
							
							
						

						}
						
												
						
					}))().start();
	
		
	}
	
	//查询商品详情
	exports.loadMerchandiseDetail=function(position,merchandiseId){
		
		exports.prodetailsShow();
		
		$("#div_merchandise_detail").html(' <div class="ldh-waiting"></div> <div class="ldh-productdetails-close" onclick="$ldh_shop.prodetailsHide()">&nbsp;</div>');
  
		var params = {
				shopId : exports.getShopId(),
				merchandiseId:merchandiseId
		};
		
		
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Goods/queryDetails.do", params));
					
					var htmlStr="";
					if(data["code"]==1){
						
						var picDefault=data.details.picDefault;
						
						if(picDefault=="" || picDefault.indexOf(".")<0){
							
							picDefault= ctx+"/v1/img/default_234_220.png";
						}else{
							
							picDefault=fileOpenSourceUrl+data.details.picDefault;
						}
																
										htmlStr += '<div class="ldh-prodts-l">';
										htmlStr += '<div class="ldh-productpic">';
										htmlStr += '<img id="picDefault" src="'+picDefault+'">';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-productbtn">';
										htmlStr += '<div class="ldh-productbtn-l"></div>';
										htmlStr += '<div class="ldh-productbtn-r"></div>';
										htmlStr += '<div class="ldh-productbtn-pic" style="width: 366px;">';
										htmlStr += '<ul style="width: 488px; left: 0px;" id="smallImageList">';
										for(var i =0;i<data.images.length;i++){
											
											var img_small=data.images[i].imgUrl,img_big="";
											
											if(validate.isNull(img_small)){
												
												img_small=ctx+"/v1/img/default_234_220.png";
												
												img_big=img_small;
												
											}else{
												
												img_big=fileOpenSourceUrl+img_small;
												
												img_small=fileOpenUrl+img_small;
												
												
											}
											
											if(i==0){
												htmlStr += '<li class="ware_pic_hover" onclick=$ldh_shop.switchImage(this,"'+img_big+'")><img width="55" height="55" src="'+img_small+'"></li>';
											}else{
												htmlStr += '<li onclick=$ldh_shop.switchImage(this,"'+img_big+'")><img width="55" height="55" src="'+img_small+'"></li>';
											}
										}
										htmlStr += '</ul>';
										htmlStr += '</div>';
										htmlStr += '</div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-prodts-r">';
										htmlStr += '<div class="ldh-prodts-title">';
										htmlStr += '<h3 id="">'+data["details"]["merchandiseName"]+'</h3>';
										htmlStr += '<p>'+data["details"]["brief"]+'</p>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-prodts-info clearfix">';
										htmlStr += '<div class="fl-left">';
										var unitName=data["details"]["unitName"];
										if(!validate.isNull(unitName)){
											
											unitName="/"+unitName;
										}
										htmlStr += '<p><span>邻店价：</span><span class="color-main">¥'+data["details"]["price"].toFixed(2)+unitName+'</span></p>';
										if(data["details"]["price"]<data["details"]["mktprice"]){
											htmlStr += '<p><span>原价：</span><s>¥'+data["details"]["mktprice"].toFixed(2)+unitName+'</s></p>';
										}
										htmlStr += '</div>';
									//	htmlStr += '<div class="fl-right"><button type="button" class="ldh-goods-sub"></button><button type="button" class="ldh-goods-add"></button></div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-prodts-btn"><p class="color-main" id="tip_add_cartnum" style="display:none;">加入购物车成功</p><br><button type="button" class="btn-green" onclick=$ldh_cart.addCartNum(this,1,"'+exports.getShopId()+'","'+data["details"]["merchandiseId"]+'","'+data["details"]["price"]+'",'+exports.getCurrentPage()+position+')>加入购物车</button></div>';
										htmlStr += '</div>';
										htmlStr += '<div class="ldh-productdetails-close" onclick="$ldh_shop.prodetailsHide()">&nbsp;</div>';
				    
										
					}
				
					$("#div_merchandise_detail").html(htmlStr);
					
					propicRoll();
					
				}))().start();

		
	};
	

	
	//切换图片
	exports.switchImage=function(obj,url){
		
		$("#smallImageList li").removeClass("ware_pic_hover");
		
		$(obj).addClass("ware_pic_hover");
		
		$("#picDefault").attr("src",url);
		
	};
	
	// 商品详情隐藏
	exports.prodetailsHide=function(){
		$(".ldh-productdetails-bg").hide();	
	};
	
	
	//商品详情出现
	exports.prodetailsShow=function(){
		
		$(".ldh-productdetails-bg").show();	
	};
	
	
	var clickable=true;
	
	//收藏商家
	exports.concernShop=function(){
		
		if(!clickable)
		{
			return;
		}
		
		clickable=false;
		
		$("#btn_favor em").html("");
		
		base.showLoading("#btn_favor em",26);
		
		var params = {
				shopId : exports.getShopId()
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Shop/concernShop.do", params));
						
						base.cancelLoading("#btn_favor em");
						
						clickable=true;
						
						if(!base.validateLoginStatus(data)){
							setConcernButton(0);
							return;
						}
						
						if(data["code"]==1){
							
							setConcernButton(1);
							
						}else if(data["code"]=="-10001"){
							alert(data["message"]);
						}
						
		}))().start();
			
	};
	
	//取消收藏商家
	exports.cancleConcernShop=function(){

		if(!clickable)
		{
			return;
		}
		
		clickable=false;
		
		$("#btn_favor em").html("");
		
		base.showLoading("#btn_favor em",26);
		
		var params = {
				shopId : exports.getShopId()
		};
		
		eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopweb/Shop/cancleConcernShop.do", params));
						
						if(!base.validateLoginStatus(data)){
							setConcernButton(1);
							return;
						}
						
						if(data["code"]==1){
							setConcernButton(0);
						}else if(data["code"]=="-10001"){
							alert(data["message"]);
						}
						base.cancelLoading("#btn_favor em");
						clickable=true;
		}))().start();
			
	};
	
	//设置收藏按钮的样式和状态
	function setConcernButton(status){
		
		if(status==1){
			//已收藏
			$("#btn_favor").css("width","54px");
			$("#btn_favor").css("background","#ed5d3a");
			$("#btn_favor").html('<em onclick="$ldh_shop.cancleConcernShop()">已收藏</em>');
			
		}else{
			//未收藏
			$("#btn_favor").css("width","48px");
			$("#btn_favor").css("background","#CC0");
			$("#btn_favor").html('<em onclick="$ldh_shop.concernShop()">收藏</em>');
			
		}
		
	}
	
	//跳转到商家二维码页面
	exports.gotoQrcode=function(){
		
		get2post(host+ctx+"/v1/pages/shop/qrcode.jsp?shopId="+exports.getShopId(),"_blank");
		
		
	};
	
	//跳转到商家相册
	exports.goShopPhoto=function(){
		
		get2post(host+ctx+"/v1/pages/shop/shopPhotos.jsp?shopId="+exports.getShopId());
		
		
	};
	

	
});

